package tgc.tdu.tgq.demo.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;

import tgc.tdu.tgq.demo.service.SysUserService;

@Controller
@SessionAttributes(value = { "user" })
public class MainController {
	@Autowired
	private SysUserService userService;
	@RequestMapping(value = { "/", "/login" }, method = RequestMethod.GET)
	public String login() {
		return "login";
	}

	@RequestMapping(value = "/main2")
	public String main2() {
		return "redirect:main";
	}
	@RequestMapping(value = "/main")
	public String main() {
		return "main";
	}
	
	@RequestMapping(value = "/stuMain")
	public String stuMain() {
		return "stuMain";
	}
	

	// Secured设置登录权限
	//@Secured(value = { "ROLE_STUDENT" })
	//用表达式来控制登录权限
//	@PreAuthorize(value = "hasRole('ROLE_STUDENT')")
//	@RequestMapping(value = "/stuMain")
//	public String stuMain() {
//		return "stuMain";
//	}

//	@RequestMapping(value = "login",method = RequestMethod.POST)
//	public String login(String username,String pwd,ModelMap modelMap) {
//		SysUser user=userService.login(username,pwd);
//		if(user==null) {
//			return "redirect:login";
//		}
//		modelMap.put("user", user);
//		if(user.isRole("ROLE_STUDENT")) {
//			return "redirect:stuMain";
//		}else {
//			return "redirect:main";
//		}
//	}

//	@RequestMapping(value = "/logout")
//	public String logout(ModelMap modelMap,HttpServletRequest request) {
//		modelMap.remove("user");
//		HttpSession session=request.getSession();
//		session.removeAttribute("user");
//		return "redirect:login";
//	}

	// 当value的值和方法名一样可以用第一种，否则只能用第二种
	// 第一种
//	@RequestMapping(value = "/main")
//	public void main() {
//		
//	}
	// 第二种
//	public String main() {
//		return "main";
//	}
}
